package com.jt.service;

import com.jt.mapper.UserMapper;
import com.jt.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import java.util.List;
import java.util.UUID;

@Service
public class UserServiceImpl implements UserService{

    @Autowired
    private UserMapper userMapper;


    @Override
    public List<User> findAll() {
        return userMapper.findAll();
    }



    @Override
    public String login(User user){
        String password = user.getPassword();
        byte[] bytes = password.getBytes();
        //1.将密码加密
        String md5Password = DigestUtils.md5DigestAsHex(bytes);
        user.setPassword(md5Password);
        //2.根据用户名和密码查询数据库
        User userDB = userMapper.findUserByUP(user);
      //3.判断userDB 是否有值
        if(userDB == null){
            //用户名和密码查询错误,返回为空
            return null;
        }
        //程序走到这里,说明用户名和密码正确 返回token
        String token =UUID.randomUUID().toString();
        return token;


    }
}
